﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QThread>
#include <QKeyEvent>
#include <QPixmap>
#include <QThread>
#include <QList>
#include <QTimer>
#include <QDateTime>
#include <QMessageBox>
#include <QHostInfo>//获取本机信息
#include <QNetworkInterface>
#include <QPalette>
#include <QColorDialog>
#include <QFontDialog>
#include <QFileDialog>
#include "UDP_Mode.h"
#include "TCP_ClientMode.h"
#include "TCP_ServerMode.h"
#include "ipinputcontrol.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_Connect_clicked();

    void on_Disconnect_clicked();
    //点击发送
    void on_Send_clicked();
    //接收消息
    void UpdateMsg(QByteArray message);
    //定时发送
    void LoopSend();
    //点击定时发送
    void on_Timer_Send_clicked();
    //清空接收区
    void on_ClearMessage_clicked();
    //累计清零
    void on_clear_send_cnt_clicked();
    //选择协议
    void on_Protoclo_currentIndexChanged(int index);
    //更新client列表
    void UpdateClientsList(QString method, QString IP);
    //域名解析
    void lookedUp(const QHostInfo &host);
    //键盘事件
    void keyPressEvent(QKeyEvent *key_event);
    //有客户端接入或断开时给出提示
    void UpdateClientsHint(QString message);

    void on_ActRecivceFont_triggered();

    void on_ActSendFont_triggered();

    void on_ActOpenFile_triggered();

    void on_ActSaveFile_triggered();

    //踢除客户端
    void on_Kick_clicked();

    void on_ActAbout_triggered();

    void on_ActSkinBlue_triggered();

    void on_ActSkinWhite_triggered();

    void on_ActSkinBlack_triggered();

signals:
    void tcpC_connect(const QString Server_ip, const quint16 Server_port);
    void tcpC_disconnect();
    void tcpC_send(QByteArray msg);

    void tcpS_open(const QString ipAddress, const quint16 port);
    void tcpS_close();
    void tcpS_send(QString ip, QByteArray msg);
    void tcpS_kick(QString ip);

    void udp_open(const QString ipAddress, const quint16 port);
    void udp_close();
    void udp_send(QByteArray msg,QString obj_ip,quint16 obj_port);
private:
    Ui::MainWindow *ui;

    QTimer *Send_timer;     //创建一个定时器,用于循环发送网络消息

    UDP_Service* UdpService; //创建一个UDP_Service类的实例
    QThread* UdpThread;
    TCP_Client* TcpClient;   //创建一个TCP_Client类的实例
    QThread* ClientThread;
    TCP_Server* TcpServer;   //创建一个TCP_Server类的实例
    QThread* ServerThread;
    //累计
    quint16 Recive_Count;
    quint16 Send_Count;
    //DNS域名解析结果
    QString DnsAnalysisResult;
    void sysInit();

    void uiInit();
    //使能
    void Enable_Options();
    //禁用
    void Disable_Options();
};

#endif // MAINWINDOW_H
